package sort.ui.components;

import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class SelectorPanel extends JPanel {
	private JComboBox cbox_algoname;
	private JTextField txt_rec_count;
	
	public static final int DEFAULT_RECORD_COUNT = 100;

	public SelectorPanel() {
		super(new GridLayout(0,2));
		add(new JLabel("Algorithm name:"));
		cbox_algoname = new JComboBox();
		cbox_algoname.setEditable(false);
		add(cbox_algoname);
		
		add(new JLabel("Record count:"));
		
		txt_rec_count = new NumberField();
		txt_rec_count.setText(String.valueOf(DEFAULT_RECORD_COUNT));
		txt_rec_count.setColumns(10);
		add(txt_rec_count);
	}
	public void setAlgorithmNames(String[] names) {
		cbox_algoname.removeAllItems();
		for ( int i=0; i<names.length; i++ ) {
			cbox_algoname.addItem(names[i]);
		}
	}
	public void addArgorythmName(String name) {
		cbox_algoname.addItem(name);
	}
	public String getArgorythmName() {
		return (String)cbox_algoname.getSelectedItem();
	}
	public int getRecordCount() {
		return Integer.parseInt(txt_rec_count.getText());
	}
	
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SelectorPanel Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
		Container container = frame.getContentPane();
		SelectorPanel panel = new SelectorPanel();
        container.add(panel);
        String names[] = {"test1","test2","test3"};
        panel.setAlgorithmNames(names);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
	}
}
